import Taro , { Component } from '@tarojs/taro';
import { View, Text , Button} from '@tarojs/components';
import UsedCardRecordFunction from '../../../components/turnove-card-record-function';
import './index.scss';

export default class Index extends Component {

  config = {
      navigationBarTitleText: '',
      enablePullDownRefresh: true,
  }

  state = {
    type: 0, // 0 静止状态 1 pulldown 2 reachBottom
  }

  componentWillMount () {}
  componentDidMount () {}
  componentWillReceiveProps (nextProps,nextContext) {}
  componentWillUnmount () {}
  componentDidShow () {}
  componentDidHide () {}
  componentDidCatchError () {}
  componentDidNotFound () {}
  onPullDownRefresh() {
    Taro.showLoading({
      mask: true
    })
    this.setState({
      type: 1
    })
  }
  onReachBottom() {
    console.log('reach bottom');
    this.setState({
      type: 2
    })
  }

  childHasChanged() {
    this.setState({
      type: 0
    }, () => {
      Taro.stopPullDownRefresh()
      Taro.hideLoading()
    })
  }
  render() {
    return (
      <View className="used-card-record">
        <UsedCardRecordFunction ref="child" onChanged={this.childHasChanged.bind(this)} type={this.state.type} />
      </View>
    );
  }
}
